/**
 * 功能描述 收费行编辑
 */

define(function (require, exports, module) {
	var Component = require("editgrid");
	
	var fetchProperties = require("../constant/fetchProperties");
	var editGridEvents = require("../handler/editGridEvents");
	
    var instance = {
        initComponent : function (params, widget) {
            var component = new Component({
            	parentNode : ".J-editgrid",	
            	model : {
                    id : "memberChargeEditGrid",
                    allowAdd : false,
                    columns : [{
                        name : "signUpRegister.personalInfo.idNumber",
                        label : "身份证号",
                    },{
                        name : "signUpRegister.personalInfo.name",
                        label : "姓名"
                    },{
                    	name : "signUpRegister.personalInfo.sex.value",
                        label : "性别"
                    },{
                    	name : "signUpRegister.personalInfo.mobilePhone",
                    	label : "手机号"
                    },{
                    	name : "signUpRegister.travelContract.productRule.product.name",
                    	label : "权证名称"
                    },{
                    	name : "signUpRegister.travelContract.memberCertificates",
                    	label : "权证号"
                    },{
                    	name : "signUpRegister.planItemGroup.payable",
                    	label : "应收金额",
                    	format:function(val){
							return Number(val).toFixed(2);
						}
                    },{
                    	name : "payable",
                    	label : "实收金额",
                    	format:function(val){
							return Number(val).toFixed(2);
						},
						editor : {
							type:"text",
							onChange : function(plugin,index,rowData){
								var income = plugin.getValue();
								var reg = "-?(0|[1-9]\d*)(\.\d+)?";
								var re = new RegExp(reg);
								if(income.search(re) != -1){
									rowData.payable = Number(plugin.getValue()).toFixed(2);
									component.update(index, rowData);
									editGridEvents.setTotal(component, widget);
									editGridEvents.fillingData(index, rowData, component);
								}else{
									Dialog.alert({
										title : "提示",
										content : "请输入正确的价格！",
									})
									rowData.payable = 0.00;
									component.update(index,rowData);
								}
							}
						}
                    },{
                    	name : "operator.name",
                    	label : "收费人"
                    },{
                    	name : "chargeDate",
                    	label : "收费日期",
                    	format: "date",
                    },{
                    	name : "signUpRegister.exitGroup",
                    	label : "是否退团",
                    	format:function(val){
							if(val){
								return "是";
							}else{
								return "否";
							}
						}
                    },{
                    	name : "refund",
                    	label : "是否退费",
                    	format:function(val){
							if(val){
								return "是";
							}else{
								return "否";
							}
						}
                    }]
                }
            });
            widget.set("editgrid", component);
        }
    };
    module.exports = instance;
});
